package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class get suppliers info from the DB 
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessagePullSupp {

	private ConnectionToClient client ;
	private String[] str; 
	/**
	 * Contractor of this class 
	 * @param str
	 * @param client
	 */
	public MessagePullSupp(String[] str, ConnectionToClient client) {
		this.client= client ;
		this.str= str; 	
	}
	/**
	 *  This method pull supplier from the DB 
	 * @throws SQLException
	 * @throws IOException
	 */
	public void PullSupp() throws SQLException, IOException{
		SQLConnection sc = new SQLConnection();
		java.sql.PreparedStatement pusu = sc.getConnection().prepareStatement("SELECT suppliers.idsuppliers FROM db.suppliers;");
		ResultSet pusurs= pusu.executeQuery();
		ArrayList<Object> pullsup=new ArrayList<Object>();
		pullsup.add("pullsupp");
		if(str[1].equals("111")) {
			pullsup.add("111");	
		}
		else if (str[1].equals("222"))
		{
			pullsup.add("222");
		}
		else if (str[1].equals("333"))
		{
			pullsup.add("333");
		}
		while (pusurs.next()){
			
			pullsup.add(pusurs.getInt(1));
		}
			
		pusurs.close();
		client.sendToClient(pullsup);
	
	}
}
